-module(drop).
-export([fall_velocity/1, fall_velocity_ex/1]).

%% @doc Calculates the velocity of an object falling on mass object
%% as if it were in a vacuum (no air resistance). The distance is
%% the height from which the object falls, specified in meters,
%% and the function returns a velocity in meters per second.
-spec(fall_velocity({atom(),number()}) -> number()).


fall_velocity(Where) ->
	{ Planemo, Distance } = Where,
	fall_velocity( Planemo, Distance ).
%% end.

fall_velocity_ex(Where) ->
	{ Planemo, Distance } = Where,
	fall_velocity_ex( Planemo, Distance ).
%% end.
	

fall_velocity(earth, Distance) when Distance >= 0 -> 
	Temp=2 * 9.8 * Distance, 
	math:sqrt(Temp);
%% end.

fall_velocity(moon, Distance) when Distance >= 0 -> 
	Temp=2 * 1.6 * Distance, 
	math:sqrt(Temp);
%% end.

fall_velocity(mars, Distance) when Distance >= 0 -> 
	Temp=2 * 3.71 * Distance, 
	math:sqrt(Temp).
%% end.


fall_velocity_ex(Planemo, Distance) when Distance >= 0  ->
	Gravity = case Planemo of
		earth -> 9.8;
		moon ->  1.6;
		mars ->  3.71
	end,  % note comma - function isn't done yet

	math:sqrt(2 * Gravity * Distance).
%% end.
